package buttons;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JTextField;
import controller.Controller;

/**
 * The text bar in the GUI that accepts user input.
 * 
 * @author Misha
 */

public class TextInput
{
    private static final int WIDTH = 600;
    private static final int HEIGHT = 30;
    JTextField myText;
    Controller myController;

    public TextInput(Controller controller)
    {
        myText = new JTextField();
        myController = controller;

        myText.addActionListener(new ActionListener()
        {
            @Override
            public void actionPerformed(ActionEvent evt)
            {
                myController.parseAndEvaluate(getText());
                myText.setText("");
            }
        });

        myText.setBorder(BorderFactory.createLoweredBevelBorder());
        myText.setPreferredSize(new Dimension(WIDTH, HEIGHT));
    }

    public JTextField getInstance()
    {
        return myText;
    }

    public String getText()
    {
        return myText.getText();
    }

    public void setText(String s)
    {
        myText.setText(s);
    }

}
